<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
%>

<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>云医通开放性接口平台</title>
<link rel="stylesheet" type="text/css" href="./css/mserver.css" />
<link rel="stylesheet" type="text/css" href="./css/calender.css" />
<link rel="stylesheet" type="text/css" href="./css/mserverother.css" />
<link rel="stylesheet" type="text/css" href="./css/tip-yellow.css" />
<link rel="stylesheet" type="text/css" href="./css/tip-darkgray.css" />
<link rel="stylesheet" type="text/css" href="./css/tableStyle.css" />
<script src="./js/jquery-1.8.0.min.js"></script>
<script src="./js/Common.js"></script>
<script src="./js/jquery.poshytip.min.js"></script>
</head>

<body>
	<div class="mserver imenu">
		<div class="header">
			<div class="inner cf">
				<a title="云医通开放性接口平台" href="Document.jsp">
					<h2>
						<span></span>
					</h2>
				</a>
				<ul>
					<li><a id="documentCenter" title="文档中心" target="_self">文档中心</a> <em style="display: block; margin-top: -1px; height: 8px;"></em></li>

					<li><a id="applicationCenter" href="javascript:void(0);" title="" target="_self">应用接入</a></li>
				</ul>
				<div class="ibtn">
					<a href="javascript:void(0);" title="登录" target="_self" class="btn_log"><span>登录</span></a> <a style="cursor: pointer;" title="设置个人信息" target="_self" class="btn_info" href="javascript:void(0);"><span>设置个人信息</span></a>
				</div>
			</div>
		</div>
		<input type="hidden" id="local_url" value="" />
		<div class="open_wrap">
			<div class="title_logo">
				<img src="./images/open_title.png" />
			</div>

			<div class="open_content">
				<div class="open_main clearfix">

					<div class="left">
						<div class="open3_menu_all">
							<h1>
								<a id="a_back" href="javascript:void(0);">返回</a>
							</h1>
							<ul class="open3_menu" style="display: block;">
							</ul>
						</div>
					</div>
					<!-- end of left -->

					<div class="right">
						<div class="api_list">
							<h1 id="api_define"></h1>
						</div>
						<p>&nbsp;</p>
						<ul class="detail_list">
							<%--返回参数--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a>返回参数</a>
									</h2>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
									<div>
										<table id="tb_responseParam" width="100%" class="kindTable kindTable2" bordercolor="#ccdee8" border="1">
											<thead>
												<tr class="blueBg">
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量名称</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量命名</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>变量类型</span></b></th>
													<th><b><span style='color: black; font-family: 宋体; font-size: 9pt; mso-bidi-font-family: "Times New Roman"; mso-font-kerning: 1.0pt; mso-ansi-language: EN-US; mso-fareast-language: ZH-CN; mso-bidi-language: AR-SA;'>说明</span></b></th>
												</tr>
											</thead>
											<tbody>
											</tbody>
										</table>
									</div>
									</p>
									<a class="more"></a>
								</div>
							</li>
							<%--返回示例--%>
							<li style="padding-bottom: 20px;">
								<div class="title">
									<h2>
										<a>返回示例</a>
									</h2>
								</div>
								<div class="theme_content" style="text-indent: 24px;">
									<p>
										<strong>示例：</strong>
									</p>
									<p id="p_responseParamstruct"></p>
									<p>
										<br />
									</p>
									<a class="more"></a>
								</div>
							</li>
						</ul>
					</div>
					<!-- end of right -->

				</div>
				<!-- end of open_main -->
			</div>
			<!-- end of open_content -->
		</div>
		<!-- end of open_wrap -->

		<div class="footer" style="clear: both; margin-top: 600px;">
			<p>Copyright &copy; 广州云医科技有限公司 2015-2016, All Rights Reserved</p>
		</div>

		<a href="#" class="go_top"></a>
	</div>

	<script type="text/javascript">
        var apiid = '';
        var apiclassid = '';
        var structid = '';

        var _variabletype = {
            "1": "number",
            "2": "string",
            "3": "struct"
        };

        // 获取接口列表信息
        function ApiList_Callback(ret) {
            if (ret) {
                var apilist = '';
                var _apidefine = '';
                var _apiname = '';

                for (var i = 0; i < ret.length; i++) {
                    _apidefine = ret[i].apidefine;
                    _apiname = ret[i].apiname;

                    if (_apidefine.length > 20)
                        _apidefine = _apidefine.substr(0, 20) + '...';
                    if (_apiname.length > 10)
                        _apiname = _apiname.substr(0, 10) + '...';

                    apilist += '<li><a name="' + ret[i].apidefine + '<br/>' + ret[i].apiname + '" title="" id="apiId_' + ret[i].apiid + '" href="ApiDetails.jsp?apiclassid=' + apiclassid + '&apiid=' + ret[i].apiid + '"><p class="english">' + _apidefine + '</p><p>' + _apiname + '</p></a></li>';
                }

                if ($.trim(apilist).length > 0) {
                    $('.open3_menu').append(apilist);
                    $('#apiId_' + apiid).addClass('now');

                    //poshytip 初始化
                    $(".open3_menu li").each(function (i) {
                        var a = $(".open3_menu li a");
                        var sid = $(a[i]).attr("id");
                        sid = "#" + sid;
                        $(sid).poshytip({
                            content: '',
                            className: 'tip-darkgray',
                            showOn: 'focus',
                            alignTo: 'target',
                            alignX: 'right',
                            alignY: 'bottom',
                            offsetX: 10,
                            showTimeout: 100
                        });
                        $(sid).poshytip('update', $(sid).attr("name"));
                        $(sid).hover(function () {
                            $(sid).poshytip("show");
                        }, function () {
                            $(sid).poshytip("hide");
                        });
                    });
                }
            }
        }

        // 获取接口信息
        function Api_Callback(ret) {
            if (ret && ret.length == 1) {
                if ($.trim(ret[0].apiclassid).length == 0 || apiclassid != ret[0].apiclassid) {
                    alert('参数错误');
                    window.location.href = "Document.jsp";
                    return;
                }
                else {
                    $('#a_back').text('返回' + ret[0].apiclassname);
                    $('#a_back').attr('href', 'API.jsp?apiclassid=' + apiclassid);
                }
            }
        }

        // 获取参数
        function ParametersByStruct_Callback(ret) {
            if (ret && ret.length > 0) {
                var html = '';
                var _parametername = '';

                for (var i = 0; i < ret.length; i++) {
                    _parametername = ret[i].parametername;

                    if (ret[i].variabletype.toString() == '3') {
                        _parametername = '<a href="StructResponse.jsp?apiclassid=' + apiclassid + '&apiid=' + apiid + '&structid=' + ret[i].childstructid + '" title="点此查看结构" target="_blank"><strong>' + _parametername + '</strong></a>';
                    }

                    html += '<tr><td><p>' + _parametername + '</p></td><td><p>' + ret[i].variablename + '</p></td><td><p>' + _variabletype[ret[i].variabletype.toString()] + '</p></td><td>' + ret[i].description + '</td></tr>';
                }

                if ($.trim(html).length > 0) {
                    $('#tb_responseParam tbody').append(html);
                    $('#tb_responseParam tr:even').addClass('blueBg');
                    $('#tb_responseParam p').attr('align', 'center');
                }
            }
        }

        // 获取参数示例
        function Paramstruct_Callback(ret) {
            if (ret && ret.length > 0) {
                if ($.trim(ret[0].example).length > 0) {
                    $('#api_define').text(ret[0].structname + ' 结构');

                    var jobj = JSON.parse(ret[0].example);
                    var str_json = JSON.stringify(jobj, null, "\t");
                    $('#p_responseParamstruct').text(str_json);
                }
            }
        }

        function CheckUrl() {
            apiid = Public.GetUrlParam('apiid');
            apiclassid = Public.GetUrlParam('apiclassid');
            structid = Public.GetUrlParam('structid');

            if ($.trim(apiid).length == 0 || $.trim(apiclassid).length == 0 || $.trim(structid).length == 0) {
                alert('参数错误');
                window.location.href = "Document.jsp";
            }
        }

        $(function () {
        	path = "<%=path%>/";
			CheckUrl();

			Public.ajaxPost(window.parent.path + apis["getApi"] + "?apiclassid=" + apiclassid, null, ApiList_Callback, null);
			Public.ajaxPost(window.parent.path + apis["getApi"] + '?apiid=' + apiid, null, Api_Callback, null);
			Public.ajaxPost(window.parent.path + apis["getParamstruct"] + '?structid=' + structid, null, Paramstruct_Callback, null);
			Public.ajaxPost(window.parent.path + apis["getParametersByStruct"] + '?structid=' + structid, null, ParametersByStruct_Callback, null);
		});
	</script>
</body>
</html>